package com.eyolas.passwordmanager.adapter;

import java.util.List;

import com.eyolas.passwordmanager.model.Account;
import com.eyolas.passwordmanager.utils.StringUtils;
import com.eyolas.passwordmanager.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * Adapter pour les comptes
 * @author Eyolas
 * @date 28 mai 2012
 */
public class AccountAdapter extends AListAdapter<Account>{
	
	
	/**
	 * @author Eyolas
	 * @date 28 mai 2012
	 * @param context
	 * @param list
	 */
	public AccountAdapter(Context context, List<Account> list) {
		super(context, list);
	}

	private class ViewHolder {
		TextView accountName;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		Account account = getItem(position);
		
		if(convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.list_account_row, null);
			holder.accountName = (TextView) convertView.findViewById(R.id.accountName);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.accountName.setText(StringUtils.ucfirst(account.getName() + " : " + StringUtils.ucfirst(account.getCategory().getName())));
		
		return convertView;
	}
	
}
